package org.bet.domain;

import org.springframework.data.mongodb.core.index.CompoundIndex;
import org.springframework.data.mongodb.core.index.CompoundIndexes;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.util.Assert;

@CompoundIndexes({
    @CompoundIndex(name = "name_idx", def = "{'syndicator.id': 1, 'name': 1}, {unique: true}")
})
public abstract class AbstractSyndicatedData extends AbstractIDAssignedObject {
	private static final long serialVersionUID = -658228222101555111L;
	
	@Indexed
	private String name;
	
	@DBRef
	private Syndicator syndicator;	
	
	private String description;
	
	public AbstractSyndicatedData(String name, Syndicator syndicator) {
//		super(generateId(id, syndicator));
		super(generateId(name, syndicator));
		
		Assert.hasText(name, "name should be not empty");
		Assert.notNull(syndicator, "syndicator should be not null");
		
		this.name = name;
		this.syndicator = syndicator;
	}

	protected static String generateId(String name, Syndicator syndicator) {
		return syndicator.getId() + ":" + name;
	}

	public Syndicator getSyndicator() {
		return syndicator;
	}

	public String getName(){
		return name;
	}
	
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	
}
